package 力扣;

/**
 * @author yyq
 * @create 2022-03-22 10:50
 */
public class leetcode151 {
    public static void main(String[] args) {
        String s = "  hello world  ";
        String[] s1 = s.split(" ");
        for (String s2 : s1) {
            if(s2.equals("")) System.out.println("111");
            System.out.println(s2);
        }
    }
    public String reverseWords(String s) {

        String[] split = s.split(" ");
        String contact="";
        int flag=0;
        int index=0;
        for (int i=split.length-1;i>=0;i--){
            if(!split[i].equals("")){
                contact=contact+split[index]+" ";
                index=i;
            }
            if(i==0){
                contact=contact+split[index];
            }

        }
        return contact;
    }

}
